var app = getApp();
var md5 = require("../../utils/md5.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  user_tel: app.globalData.userTel,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  bindCancel: function () {
    wx.navigateBack({})
  },
  bindSave: function (e) {
    var that = this;
    var user_name = e.detail.value.user_name;
    var user_sex = e.detail.value.user_sex;
    var user_tel = that.data.user_tel;
    var user_age = e.detail.value.user_age;
    var amount = e.detail.value.amount;
    if (user_name == "") {
      wx.showModal({
        title: '错误',
        content: '请填写名字',
        showCancel: false
      })
      return
    }
    if (user_sex == "") {
        wx.showModal({
          title: '错误',
          content: '请选择性别',
          showCancel: false
        })
        return
      }
    if (user_age == "") {
        wx.showModal({
          title: '错误',
          content: '请填写年龄',
          showCancel: false
        })
        return
      }
    if (amount == "" || amount * 1 < 30 ) {
        wx.showModal({
          title: '错误',
          content: '请填写正确的提现金额',
          showCancel: false
        })
        return
      }
//    if (30 > app.globalData.userAccount * 1) {
//        wx.showModal({
//          title: '错误',
//          content: '余额不足，无法提现',
//          showCancel: false
//        })
//        return
//      }
    var money = amount;
    var open_id = app.globalData.openId;
    var service = 'User.GetMoney';
    var user_id = app.globalData.userId;
    var sign = md5.md5(money + open_id + service + user_age + user_id + user_name + user_sex + user_tel);
    
    wx.request({
      url: app.globalData.serviceUrl + 'User.GetMoney',
      header: {
        'Content-Type': 'json'
      },
      data: {
        sign: sign,
        money: amount,
        open_id: open_id,
        user_id: user_id,
        user_age: user_age,
        user_name: user_name,
        user_sex: user_sex,
        user_tel: user_tel,
      },
      success: function (res) {
    	var result = res.data.data;
        if (result.code == 0) {
          wx.showModal({
            title: '成功',
            content: '您的提现申请已提交，等待财务打款',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                that.bindCancel();
              }
            }
          })
        } else {
          wx.showModal({
            title: '错误',
            content: result.info,
            showCancel: false
          })
        }
      },
      complete: function(res) {
  		console.log(res);
        },
    })
  }
})